/*************************************************************************
	> File Name: P1093.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-08 10:29:01
 ************************************************************************/
#include <iostream>
#include <algorithm>
using namespace std;

struct Stu {
    int id;
    int yu, shu, ying, sum;
} arr[305];

bool cmp(Stu a, Stu b) {
    if (a.sum != b.sum) return a.sum > b.sum;
    if (a.yu != b.yu) return a.yu > b.yu;
    return a.id < b.id;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i].yu >> arr[i].shu >> arr[i].ying;
        arr[i].id = i + 1;
        arr[i].sum = arr[i].yu + arr[i].shu + arr[i].ying;
    }
    sort(arr, arr + n, cmp);
    for (int i = 0; i < 5; i++) {
        cout << arr[i].id << " " << arr[i].sum << endl;
    }
    return 0;
}
